Skip to content

feat(schema_cache): column type + query #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

juleswritescode
Copy link
Collaborator

@juleswritescode juleswritescode commented Dec 19, 2024

Introduces an all-new, immediately-usable, delivered-straight-to-your-door data type in the SchemaCache: the Column.

The next step is to use that data type in the pg_completions crate – so we can suggest columns in a select clause, based on the queried table.

I wrote the query myself, with a little bit of help from ChatGPT and the postgres docs, so please make sure it follows best practices. 🙌🏻

Also wrote and renamed a test, and added full features for tokio on workspace level.

@juleswritescode juleswritescode marked this pull request as ready for review December 20, 2024 16:12
@juleswritescode juleswritescode changed the title Schema cache/columns feat(schema_cache): column type + query Dec 20, 2024
Comment on lines +21 to +22
unnest (ix.indkey) as attnum,
ix.indisprimary as is_primary,
Copy link
Collaborator Author

@juleswritescode juleswritescode Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if we're using compound indexes, e.g. (user_id, tax_number), we'd have is_primary == true for tax_number.

This might be problematic for index suggestions etc. – wdyt?

Copy link
Collaborator

@psteinroe psteinroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the effort to write a custom query, but what didn't you like from this one? :D

https://github.com/supabase/postgres-meta/blob/master/src/lib/sql/columns.sql

@juleswritescode
Copy link
Collaborator Author

juleswritescode commented Jan 2, 2025

@psteinroe Ah, I wasn't aware of the postgres-meta repo at all, I only took a look at this one... 🙈

We can use the postgres-meta query if you prefer, it's probably battle-proven.

But it does lack some info that seemed to me like we might need it in the future:

  • the type_id which we could use to find the relevant type on the SchemaCache
  • whether the column is a primary key
  • the max length of the col if it's a varchar

Of course I'm not sure whether we'll need that data and whether the query fetches it 100% correctly. :)

Would you like me to use my query, the untouched postgres-meta query, or the postgres-meta query updated with those properties?

@psteinroe
Copy link
Collaborator

let's use yours and we keep it in mind when issues come up that it might be worth to go to postgrest-meta for it

@psteinroe psteinroe merged commit edd57ae into supabase-community:main Jan 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants